from app.extensions import db
from datetime import datetime
class Order(db.Model):
    __tablename__ = 'orders'
    order_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    order_no = db.Column(db.String(32), unique=True, nullable=False)
    tenant_id = db.Column(db.Integer, db.ForeignKey('users.userid'), nullable=False)
    house_id = db.Column(db.Integer, db.ForeignKey('houseinfo.houseid'), nullable=False)
    landlord_id = db.Column(db.Integer, db.ForeignKey('users.userid'), nullable=False)
    start_date = db.Column(db.Date, nullable=False)
    end_date = db.Column(db.Date, nullable=False)
    total_amount = db.Column(db.Integer, nullable=False)
    deposit = db.Column(db.Integer, nullable=False)
    status = db.Column(db.Enum('pending', 'confirmed', 'completed', 'canceled', 'disputed'),nullable=False, default='pending')
    cancel_reason = db.Column(db.String(255))
    cancel_by = db.Column(db.Enum('tenant', 'landlord', 'system'))
    created_at = db.Column(db.TIMESTAMP, default=datetime.now)
    updated_at = db.Column(db.TIMESTAMP, default=datetime.now, onupdate=datetime.now)
